<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <template id="t1">
      <div>
        {{lastName}} {{firstName}}
        <hr />
        {{info}}
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
      const vm = new Vue({
        el: "#app",
        template: "#t1",
        data: {
          firstName: "li",
          lastName: "jack",
          info: {
            age: 10,
            size: {
              w: 100,
              h: 200,
            },
          },
        },
        watch: {
          info: {
            handler(newVal, oldValue) {
              console.log(newVal, oldValue);
            },
            // 深度侦听
            deep: true,
          },
          "info.age": {
            handler(newVal, oldValue) {
              // console.log(newVal, oldValue);
            },
            // 初始化立刻执行一次handler
            // immediate: true,
          },
          "info.size.w"(newVal, oldValue) {
            // console.log(newVal, oldValue);
          },
          firstName(newVal, oldValue) {
            console.log(newVal, oldValue);
          },
          lastName(newVal, oldValue) {
            console.log(newVal, oldValue);
          },
        },
      });

      vm.age = 20;
    </script>
  </body>
</html>
